{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f57147c2-5689-48be-b029-a84bfa52b31a",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "downloading uv 0.9.2 aarch64-unknown-linux-gnu\n",
      "no checksums to verify\n",
      "installing to /home/zmrobo/.local/bin\n",
      "  uv\n",
      "  uvx\n",
      "everything's installed!\n",
      "\n",
      "To add $HOME/.local/bin to your PATH, either restart your shell or run:\n",
      "\n",
      "    source $HOME/.local/bin/env (sh, bash, zsh)\n",
      "    source $HOME/.local/bin/env.fish (fish)\n"
     ]
    }
   ],
   "source": [
    "# 如果已经装过可跳过,新系统只需要安装一次\n",
    "!curl -LsSf https://astral.sh/uv/install.sh | sh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3c84e581-296f-4009-aace-4e49c10c35a1",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import os, sys\n",
    "# 把 uv 所在目录写进 PATH\n",
    "os.environ[\"PATH\"] = f\"/home/zmrobo/.local/bin:{os.environ['PATH']}\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4e27c542-a2d0-404e-8cfc-4ebd10158cef",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import os\n",
    "if '/home/zmrobo/.local/bin' not in os.environ['PATH']:\n",
    "    os.environ['PATH'] = f\"/home/zmrobo/.local/bin:{os.environ['PATH']}\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "c49cc4bb-bfdb-4d4b-a24f-67ccbbc3cbcd",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using CPython \u001b[36m3.12.12\u001b[39m\n",
      "Creating virtual environment at: \u001b[36m.venv\u001b[39m\n",
      "\u001b[33m?\u001b[0m \u001b[1mA virtual environment already exists at `.venv`. Do you want to replace it?\u001b[0m \u001b[38;5;8m[y/n]\u001b[0m \u001b[38;5;8m›\u001b[0m \u001b[36myes\u001b[0m\n",
      "\n",
      "\u001b[36m\u001b[1mhint\u001b[0m\u001b[1m:\u001b[0m Use the `\u001b[32m--clear\u001b[39m` flag or set `\u001b[32mUV_VENV_CLEAR=1\u001b[39m` to skip this prompt\u001b[?25l\u001b[?25h\n"
     ]
    }
   ],
   "source": [
    "!uv venv .venv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "ecbd1f10-3a50-4d5d-912f-3b25c2cd2643",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/usr/bin/python3\n",
      "1.21.6\n"
     ]
    }
   ],
   "source": [
    "import sys, numpy\n",
    "print(sys.executable)   # 应该指向 .venv/bin/python\n",
    "print(numpy.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "603593c4-bdbb-4c9f-94b6-47956e4dc132",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "uv 0.9.2\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "os.environ[\"PATH\"] = f\"/home/zmrobo/.local/bin:{os.environ['PATH']}\"\n",
    "!uv --version"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "81d6ba11-b55c-4126-89a1-fcab555603f9",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/zmrobo/Project/test\n"
     ]
    }
   ],
   "source": [
    "!pwd\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "312755a8-3395-479a-8573-02b6810ba41b",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "!rm -rf /home/zmrobo/Project/test/.venv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "286b771a-3a91-4805-92e7-4ffa3eaeb8ce",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using CPython \u001b[36m3.12.12\u001b[39m\n",
      "Creating virtual environment at: \u001b[36m.venv\u001b[39m\n",
      "Activate with: \u001b[32msource .venv/bin/activate\u001b[39m\n"
     ]
    }
   ],
   "source": [
    "!uv venv /home/zmrobo/Project/test/.venv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "cfbcce34-b8e7-4612-b137-dbb887329856",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "!source .venv/bin/activate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "5061fd8f-ee1a-4c2e-a117-22735c85b7f4",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[2K\u001b[2mResolved \u001b[1m30 packages\u001b[0m \u001b[2min 2.27s\u001b[0m\u001b[0m                                        \u001b[0m\n",
      "\u001b[2K\u001b[2mPrepared \u001b[1m1 package\u001b[0m \u001b[2min 9.36s\u001b[0m\u001b[0m                                              \n",
      "\u001b[2K\u001b[2mInstalled \u001b[1m30 packages\u001b[0m \u001b[2min 343ms\u001b[0m\u001b[0m                              \u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1masttokens\u001b[0m\u001b[2m==3.0.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mcomm\u001b[0m\u001b[2m==0.2.3\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mdebugpy\u001b[0m\u001b[2m==1.8.17\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mdecorator\u001b[0m\u001b[2m==5.2.1\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mexecuting\u001b[0m\u001b[2m==2.2.1\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mipykernel\u001b[0m\u001b[2m==7.0.1\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mipython\u001b[0m\u001b[2m==9.6.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mipython-pygments-lexers\u001b[0m\u001b[2m==1.1.1\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mjedi\u001b[0m\u001b[2m==0.19.2\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mjupyter-client\u001b[0m\u001b[2m==8.6.3\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mjupyter-core\u001b[0m\u001b[2m==5.8.1\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mmatplotlib-inline\u001b[0m\u001b[2m==0.1.7\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mnest-asyncio\u001b[0m\u001b[2m==1.6.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mpackaging\u001b[0m\u001b[2m==25.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mparso\u001b[0m\u001b[2m==0.8.5\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mpexpect\u001b[0m\u001b[2m==4.9.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mpip\u001b[0m\u001b[2m==25.2\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mplatformdirs\u001b[0m\u001b[2m==4.5.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mprompt-toolkit\u001b[0m\u001b[2m==3.0.52\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mpsutil\u001b[0m\u001b[2m==7.1.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mptyprocess\u001b[0m\u001b[2m==0.7.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mpure-eval\u001b[0m\u001b[2m==0.2.3\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mpygments\u001b[0m\u001b[2m==2.19.2\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mpython-dateutil\u001b[0m\u001b[2m==2.9.0.post0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mpyzmq\u001b[0m\u001b[2m==27.1.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1msix\u001b[0m\u001b[2m==1.17.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mstack-data\u001b[0m\u001b[2m==0.6.3\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mtornado\u001b[0m\u001b[2m==6.5.2\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mtraitlets\u001b[0m\u001b[2m==5.14.3\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mwcwidth\u001b[0m\u001b[2m==0.2.14\u001b[0m\n",
      "Installed kernelspec uv-env in /home/zmrobo/.local/share/jupyter/kernels/uv-env\n"
     ]
    }
   ],
   "source": [
    "# 1. 用 uv 直接装 pip + ipykernel\n",
    "!uv pip install --python .venv/bin/python pip ipykernel\n",
    "\n",
    "# 2. 注册内核\n",
    "! .venv/bin/python -m ipykernel install --user --name=uv-env --display-name \"Python (uv-env)\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e0fc31e6-3614-43ae-bdf6-32620723f64a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/zmrobo/Project/test/.venv/bin/python\n",
      "2.3.3\n"
     ]
    }
   ],
   "source": [
    "import sys, numpy\n",
    "print(sys.executable)   # 应该指向 .../工作目录/.venv/bin/python\n",
    "print(numpy.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "5afbd0a1-7db0-4280-9e54-c7fe0a14ed51",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n",
      "Requirement already satisfied: numpy in ./.venv/lib/python3.12/site-packages (2.3.3)\n",
      "Collecting pandas\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/57/56/cf2dbe1a3f5271370669475ead12ce77c61726ffd19a35546e31aa8edf4e/pandas-2.3.3-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (11.7 MB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m11.7/11.7 MB\u001b[0m \u001b[31m384.9 kB/s\u001b[0m  \u001b[33m0:00:34\u001b[0m0:00:01\u001b[0m00:02\u001b[0m\n",
      "\u001b[?25hRequirement already satisfied: python-dateutil>=2.8.2 in ./.venv/lib/python3.12/site-packages (from pandas) (2.9.0.post0)\n",
      "Collecting pytz>=2020.1 (from pandas)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/81/c4/34e93fe5f5429d7570ec1fa436f1986fb1f00c3e0f43a589fe2bbcd22c3f/pytz-2025.2-py2.py3-none-any.whl (509 kB)\n",
      "Collecting tzdata>=2022.7 (from pandas)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5c/23/c7abc0ca0a1526a0774eca151daeb8de62ec457e77262b66b359c3c7679e/tzdata-2025.2-py2.py3-none-any.whl (347 kB)\n",
      "Requirement already satisfied: six>=1.5 in ./.venv/lib/python3.12/site-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\n",
      "Installing collected packages: pytz, tzdata, pandas\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3/3\u001b[0m [pandas]2m2/3\u001b[0m [pandas]\n",
      "\u001b[1A\u001b[2KSuccessfully installed pandas-2.3.3 pytz-2025.2 tzdata-2025.2\n"
     ]
    }
   ],
   "source": [
    "! .venv/bin/python -m pip install numpy pandas -i https://pypi.tuna.tsinghua.edu.cn/simple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "06d252b3-d1c6-499c-b342-2020f807231e",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "g = 9.8                       # 重力加速度\n",
    "t = np.arange(0.1, 2.1, 0.1)  # 时间 0.1~2.0 s，间隔 0.1 s\n",
    "v = g * t                     # 末速度 v = g·t\n",
    "\n",
    "# 加一点测量误差，更“真实”\n",
    "np.random.seed(42)\n",
    "v = v + np.random.normal(0, 0.3, size=v.shape)\n",
    "\n",
    "# 保留两位小数\n",
    "t = np.round(t, 2)\n",
    "v = np.round(v, 2)\n",
    "\n",
    "# 保存成 csv，两列：时间/s  速度/(m/s)\n",
    "df = pd.DataFrame({'time_s': t, 'speed_ms': v})\n",
    "df.to_csv('freefall.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "28e808d6-03d5-4fe4-ac71-0d35f3df9400",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Linux H2-RCU 4.19.232 #145 SMP Tue Sep 30 16:37:20 CST 2025 aarch64 GNU/Linux\n",
      "Architecture:        aarch64\n",
      "Byte Order:          Little Endian\n",
      "CPU(s):              4\n",
      "On-line CPU(s) list: 0-3\n",
      "Thread(s) per core:  1\n",
      "Core(s) per socket:  4\n",
      "Socket(s):           1\n",
      "Vendor ID:           ARM\n",
      "Model:               0\n",
      "Model name:          Cortex-A55\n",
      "              total        used        free      shared  buff/cache   available\n",
      "Mem:          1.9Gi       445Mi       197Mi       101Mi       1.3Gi       1.4Gi\n",
      "Swap:            0B          0B          0B\n",
      "/dev/root        14G   13G  1.1G   92% /\n",
      "devtmpfs        977M  8.0K  977M    1% /dev\n",
      "tmpfs           986M  1.5M  984M    1% /dev/shm\n",
      "tmpfs           986M   96M  891M   10% /run\n",
      "tmpfs           5.0M  4.0K  5.0M    1% /run/lock\n",
      "tmpfs           986M     0  986M    0% /sys/fs/cgroup\n",
      "tmpfs           986M  8.0K  986M    1% /tmp\n",
      "/dev/mmcblk0p7  123M   13M  104M   11% /oem\n",
      "/dev/mmcblk0p8  362M   23K  362M    1% /userdata\n",
      "tmpfs           198M  8.0K  198M    1% /run/user/1000\n",
      "tmpfs           198M     0  198M    0% /run/user/0\n",
      "No GPU\n",
      "Python 2.7.16\n",
      "Python 3.7.3\n",
      "pip 24.0 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)\n",
      "git version 2.20.1\n",
      "/usr/bin/gcc\n",
      "gcc (Debian 8.3.0-6) 8.3.0\n",
      "Copyright (C) 2018 Free Software Foundation, Inc.\n",
      "This is free software; see the source for copying conditions.  There is NO\n",
      "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
      "\n",
      "ping: socket: 不允许的操作\n"
     ]
    }
   ],
   "source": [
    "# 1.1 系统 & 硬件\n",
    "!uname -a                    # OS / 内核\n",
    "!lscpu | head -10            # CPU 型号 & 核数\n",
    "!free -h                     # 内存\n",
    "!df -h | grep '/'            # 磁盘剩余\n",
    "!nvidia-smi 2>/dev/null || echo \"No GPU\"   # GPU 型号 / 显存\n",
    "\n",
    "# 1.2 预装软件版本\n",
    "!python --version\n",
    "!python3 --version\n",
    "!pip --version\n",
    "!git --version\n",
    "!which gcc && gcc --version  # 编译器\n",
    "\n",
    "# 1.3 网络连通性（可选）\n",
    "!ping -c 2 gitee.com"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "7faeab45-1085-43ab-b052-574b7886638c",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n",
      "Collecting torch\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/49/0c/2fd4df0d83a495bb5e54dca4474c4ec5f9c62db185421563deeb5dabf609/torch-2.8.0-cp312-cp312-manylinux_2_28_aarch64.whl (101.9 MB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.3/101.9 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m0m\n",
      "\u001b[?25h\u001b[33m  WARNING: Connection timed out while downloading.\u001b[0m\u001b[33m\n",
      "\u001b[0m\u001b[33m  WARNING: Attempting to resume incomplete download (262 kB/101.9 MB, attempt 1)\u001b[0m\u001b[33m\n",
      "\u001b[0m  Resuming download https://pypi.tuna.tsinghua.edu.cn/packages/49/0c/2fd4df0d83a495bb5e54dca4474c4ec5f9c62db185421563deeb5dabf609/torch-2.8.0-cp312-cp312-manylinux_2_28_aarch64.whl (262 kB/101.9 MB)\n",
      "\u001b[2K     \u001b[91m━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m16.3/101.9 MB\u001b[0m \u001b[31m166.5 kB/s\u001b[0m eta \u001b[36m0:08:35\u001b[0m\n",
      "\u001b[?25h\u001b[33m  WARNING: Connection timed out while downloading.\u001b[0m\u001b[33m\n",
      "\u001b[0m\u001b[33m  WARNING: Attempting to resume incomplete download (16.3 MB/101.9 MB, attempt 2)\u001b[0m\u001b[33m\n",
      "\u001b[0m  Resuming download https://pypi.tuna.tsinghua.edu.cn/packages/49/0c/2fd4df0d83a495bb5e54dca4474c4ec5f9c62db185421563deeb5dabf609/torch-2.8.0-cp312-cp312-manylinux_2_28_aarch64.whl (16.3 MB/101.9 MB)\n",
      "\u001b[2K     \u001b[91m━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m43.3/101.9 MB\u001b[0m \u001b[31m534.7 kB/s\u001b[0m eta \u001b[36m0:01:50\u001b[0m\n",
      "\u001b[?25h\u001b[33m  WARNING: Connection timed out while downloading.\u001b[0m\u001b[33m\n",
      "\u001b[0m\u001b[33m  WARNING: Attempting to resume incomplete download (43.3 MB/101.9 MB, attempt 3)\u001b[0m\u001b[33m\n",
      "\u001b[0m  Resuming download https://pypi.tuna.tsinghua.edu.cn/packages/49/0c/2fd4df0d83a495bb5e54dca4474c4ec5f9c62db185421563deeb5dabf609/torch-2.8.0-cp312-cp312-manylinux_2_28_aarch64.whl (43.3 MB/101.9 MB)\n",
      "\u001b[2K     \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━━\u001b[0m \u001b[32m70.3/101.9 MB\u001b[0m \u001b[31m227.1 kB/s\u001b[0m eta \u001b[36m0:02:20\u001b[0m\n",
      "\u001b[?25h\u001b[33m  WARNING: Connection timed out while downloading.\u001b[0m\u001b[33m\n",
      "\u001b[0m\u001b[33m  WARNING: Attempting to resume incomplete download (70.3 MB/101.9 MB, attempt 4)\u001b[0m\u001b[33m\n",
      "\u001b[0m  Resuming download https://pypi.tuna.tsinghua.edu.cn/packages/49/0c/2fd4df0d83a495bb5e54dca4474c4ec5f9c62db185421563deeb5dabf609/torch-2.8.0-cp312-cp312-manylinux_2_28_aarch64.whl (70.3 MB/101.9 MB)\n",
      "\u001b[2K     \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m100.7/101.9 MB\u001b[0m \u001b[31m341.3 kB/s\u001b[0m eta \u001b[36m0:00:04\u001b[0m00:09\u001b[0m\n",
      "\u001b[?25h\u001b[33m  WARNING: Connection timed out while downloading.\u001b[0m\u001b[33m\n",
      "\u001b[0m\u001b[33m  WARNING: Attempting to resume incomplete download (100.7 MB/101.9 MB, attempt 5)\u001b[0m\u001b[33m\n",
      "\u001b[0m  Resuming download https://pypi.tuna.tsinghua.edu.cn/packages/49/0c/2fd4df0d83a495bb5e54dca4474c4ec5f9c62db185421563deeb5dabf609/torch-2.8.0-cp312-cp312-manylinux_2_28_aarch64.whl (100.7 MB/101.9 MB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m101.9/101.9 MB\u001b[0m \u001b[31m469.1 kB/s\u001b[0m  \u001b[33m0:00:02\u001b[0m00:01\u001b[0m\n",
      "\u001b[?25hCollecting filelock (from torch)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/76/91/7216b27286936c16f5b4d0c530087e4a54eead683e6b0b73dd0c64844af6/filelock-3.20.0-py3-none-any.whl (16 kB)\n",
      "Collecting typing-extensions>=4.10.0 (from torch)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/18/67/36e9267722cc04a6b9f15c7f3441c2363321a3ea07da7ae0c0707beb2a9c/typing_extensions-4.15.0-py3-none-any.whl (44 kB)\n",
      "Collecting setuptools (from torch)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a3/dc/17031897dae0efacfea57dfd3a82fdd2a2aeb58e0ff71b77b87e44edc772/setuptools-80.9.0-py3-none-any.whl (1.2 MB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m1.3 MB/s\u001b[0m  \u001b[33m0:00:00\u001b[0m eta \u001b[36m0:00:01\u001b[0m\n",
      "\u001b[?25hCollecting sympy>=1.13.3 (from torch)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a2/09/77d55d46fd61b4a135c444fc97158ef34a095e5681d0a6c10b75bf356191/sympy-1.14.0-py3-none-any.whl (6.3 MB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.3/6.3 MB\u001b[0m \u001b[31m454.7 kB/s\u001b[0m  \u001b[33m0:00:13\u001b[0m eta \u001b[36m0:00:01\u001b[0m\n",
      "\u001b[?25hCollecting networkx (from torch)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/eb/8d/776adee7bbf76365fdd7f2552710282c79a4ead5d2a46408c9043a2b70ba/networkx-3.5-py3-none-any.whl (2.0 MB)\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m823.8 kB/s\u001b[0m  \u001b[33m0:00:04\u001b[0m eta \u001b[36m0:00:01\u001b[0m\n",
      "\u001b[?25hCollecting jinja2 (from torch)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl (134 kB)\n",
      "Collecting fsspec (from torch)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/47/71/70db47e4f6ce3e5c37a607355f80da8860a33226be640226ac52cb05ef2e/fsspec-2025.9.0-py3-none-any.whl (199 kB)\n",
      "Collecting mpmath<1.4,>=1.1.0 (from sympy>=1.13.3->torch)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/43/e3/7d92a15f894aa0c9c4b49b8ee9ac9850d6e63b03c9c32c0367a13ae62209/mpmath-1.3.0-py3-none-any.whl (536 kB)\n",
      "Collecting MarkupSafe>=2.0 (from jinja2->torch)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/1e/2c/799f4742efc39633a1b54a92eec4082e4f815314869865d876824c257c1e/markupsafe-3.0.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (24 kB)\n",
      "Installing collected packages: mpmath, typing-extensions, sympy, setuptools, networkx, MarkupSafe, fsspec, filelock, jinja2, torch\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m10/10\u001b[0m [torch]m 9/10\u001b[0m [torch]]k]e]nsions]\n",
      "\u001b[1A\u001b[2KSuccessfully installed MarkupSafe-3.0.3 filelock-3.20.0 fsspec-2025.9.0 jinja2-3.1.6 mpmath-1.3.0 networkx-3.5 setuptools-80.9.0 sympy-1.14.0 torch-2.8.0 typing-extensions-4.15.0\n"
     ]
    }
   ],
   "source": [
    "! .venv/bin/python -m pip install torch  -i https://pypi.tuna.tsinghua.edu.cn/simple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "a241e9b5-d40e-479b-a512-382a6eb85c94",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[2K\u001b[2mResolved \u001b[1m29 packages\u001b[0m \u001b[2min 5.01s\u001b[0m\u001b[0m                                        \u001b[0m\n",
      "\u001b[2K\u001b[2mPrepared \u001b[1m16 packages\u001b[0m \u001b[2min 34.31s\u001b[0m\u001b[0m                                           \n",
      "\u001b[2K\u001b[2mInstalled \u001b[1m16 packages\u001b[0m \u001b[2min 467ms\u001b[0m\u001b[0m                              \u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1maccelerate\u001b[0m\u001b[2m==1.10.1\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mcertifi\u001b[0m\u001b[2m==2025.10.5\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mcharset-normalizer\u001b[0m\u001b[2m==3.4.4\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mhf-xet\u001b[0m\u001b[2m==1.1.10\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mhuggingface-hub\u001b[0m\u001b[2m==0.35.3\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1midna\u001b[0m\u001b[2m==3.11\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mmodelscope\u001b[0m\u001b[2m==1.30.0\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mpyyaml\u001b[0m\u001b[2m==6.0.3\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mregex\u001b[0m\u001b[2m==2025.9.18\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mrequests\u001b[0m\u001b[2m==2.32.5\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1msafetensors\u001b[0m\u001b[2m==0.6.2\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1msentencepiece\u001b[0m\u001b[2m==0.2.1\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mtokenizers\u001b[0m\u001b[2m==0.22.1\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mtqdm\u001b[0m\u001b[2m==4.67.1\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mtransformers\u001b[0m\u001b[2m==4.57.1\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1murllib3\u001b[0m\u001b[2m==2.5.0\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!uv pip install --python .venv/bin/python \\\n",
    "    transformers accelerate sentencepiece modelscope -i https://mirrors.aliyun.com/pypi/simple/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "fcb79cbe-63b8-4742-a484-8395351bfc50",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "============================================================\n",
      "🔍 Python 运行环境\n",
      "============================================================\n",
      "Python: 3.12.12 (main, Oct 10 2025, 12:48:33) [Clang 20.1.4 ]\n",
      "Platform: Linux-4.19.232-aarch64-with-glibc2.28\n",
      "PWD: /home/zmrobo/Project/test\n",
      "============================================================\n",
      "torch           2.8.0\n",
      "transformers    4.57.1\n",
      "accelerate      1.10.1\n",
      "sentencepiece   0.2.1\n",
      "modelscope      1.30.0\n",
      "\n",
      "🔍 资源快照\n",
      "Memory Total   : 1.9 GB\n",
      "Memory Free    : 1.2 GB\n",
      "GPU Available  : False\n",
      "============================================================\n"
     ]
    }
   ],
   "source": [
    "import sys, os, platform, subprocess, importlib.metadata, psutil, torch\n",
    " \n",
    "print(\"=\" * 60)\n",
    "print(\"🔍 Python 运行环境\")\n",
    "print(\"=\" * 60)\n",
    "print(\"Python:\", sys.version)\n",
    "print(\"Platform:\", platform.platform())\n",
    "print(\"PWD:\", os.getcwd())\n",
    "print(\"=\" * 60)\n",
    " \n",
    "# 2.1 关键库版本\n",
    "libs = [\"torch\", \"transformers\", \"accelerate\", \"sentencepiece\", \"modelscope\"]\n",
    "for lib in libs:\n",
    "    try:\n",
    "        ver = pkg_resources.get_distribution(lib).version\n",
    "        print(f\"{lib:<15} {ver}\")\n",
    "    except:\n",
    "        print(f\"{lib:<15} ❌ 未安装\")\n",
    " \n",
    "# 2.2 硬件资源\n",
    "mem = psutil.virtual_memory()\n",
    "print(\"\\n🔍 资源快照\")\n",
    "print(f\"Memory Total   : {mem.total/1024**3:.1f} GB\")\n",
    "print(f\"Memory Free    : {mem.available/1024**3:.1f} GB\")\n",
    "print(f\"GPU Available  : {torch.cuda.is_available()}\")\n",
    "if torch.cuda.is_available():\n",
    "    for i in range(torch.cuda.device_count()):\n",
    "        print(f\"  - GPU {i}     : {torch.cuda.get_device_name(i)} \"\n",
    "              f\"{torch.cuda.memory_reserved(i)/1024**3:.1f} GB\")\n",
    " \n",
    "print(\"=\" * 60)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "88223a2b-f478-42e4-b172-482b9e9a43c3",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[2K\u001b[2mResolved \u001b[1m20 packages\u001b[0m \u001b[2min 13.86s\u001b[0m\u001b[0m                                       \u001b[0m\n",
      "\u001b[2K\u001b[2mPrepared \u001b[1m3 packages\u001b[0m \u001b[2min 3.33s\u001b[0m\u001b[0m                                             \n",
      "\u001b[2K\u001b[2mInstalled \u001b[1m3 packages\u001b[0m \u001b[2min 30ms\u001b[0m\u001b[0m.0.15                           \u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mipywidgets\u001b[0m\u001b[2m==8.1.7\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mjupyterlab-widgets\u001b[0m\u001b[2m==3.0.15\u001b[0m\n",
      " \u001b[32m+\u001b[39m \u001b[1mwidgetsnbextension\u001b[0m\u001b[2m==4.0.14\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "# 清华源\n",
    "!UV_HTTP_TIMEOUT=300 uv pip install --python .venv/bin/python ipywidgets -i https://pypi.tuna.tsinghua.edu.cn/simple/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "41f0a374-1d2a-450a-8568-c1d60140c1cf",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "文件系统        容量  已用  可用 已用% 挂载点\n",
      "/dev/root        14G   13G  190M   99% /\n"
     ]
    }
   ],
   "source": [
    "!df -h /home"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "1c7a2392-ff1c-47aa-ad4a-cf8e1bc9ec45",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Clearing cache at: \u001b[36m/home/zmrobo/.cache/uv\u001b[39m\n",
      "\u001b[2KRemoved 38405 files (\u001b[32m1.2GiB\u001b[39m)=========>] 100%                                            \n"
     ]
    }
   ],
   "source": [
    "!uv cache clean\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e8ee431-3a9d-4c48-a562-910d31d228f7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "49cbb043-f27b-434c-ab3c-89b9b2fde1f3",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "⚠️  无 GPU，仅 CPU 推理，速度会慢\n",
      "✅ transformers 可用\n",
      "LLM 环境就绪？ ✅ 可以跑\n"
     ]
    }
   ],
   "source": [
    "def llm_ready():\n",
    "    ok = True\n",
    "    if sys.version_info < (3, 7):\n",
    "        print(\"❌ Python 版本过低，建议 ≥3.8\")\n",
    "        ok = False\n",
    "    if torch.__version__ < \"1.10\":\n",
    "        print(\"⚠️  PyTorch 版本较低，可能影响性能\")\n",
    "    if not torch.cuda.is_available():\n",
    "        print(\"⚠️  无 GPU，仅 CPU 推理，速度会慢\")\n",
    "    try:\n",
    "        from transformers import AutoTokenizer, AutoModel\n",
    "        print(\"✅ transformers 可用\")\n",
    "    except ImportError:\n",
    "        print(\"❌ 未安装 transformers\")\n",
    "        ok = False\n",
    "    return ok\n",
    "\n",
    "print(\"LLM 环境就绪？\" , \"✅ 可以跑\" if llm_ready() else \"❌ 需升级/安装\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5874ba4-2cfa-462c-b31e-46d0054bd18e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (lingxin-uv-env)",
   "language": "python",
   "name": "uv-env"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
